package com.ghbank.rdws.common.lifecycle;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractLifeCycle implements LifeCycle {
    protected volatile boolean running = false; // 是否处于运行中

    public boolean isStart() {
        return running;
    }

    public void start() {
        if (running) {
            return;
        }

        running = true;
    }

    public void stop() {
        if (!running) {
            return;
        }

        running = false;
    }

    public void abort(String why, Throwable e) {
        log.error("abort caused by " + why, e);
        stop();
    }

    public boolean isStop() {
        return !isStart();
    }
}
